'''
文件名称修改，根据文件夹名称
'''

import os
import re
cpath = os.getcwd()
print('当前路径: ' + cpath)
count = 0

# 切换文件的名称
def renameFile(dirName, dirpath):
    global count
    print('处理路径: ' + dirpath)
    dirs = os.listdir(dirpath)
    os.chdir(dirpath)
    for file in dirs:
        nowfile = os.path.join(dirpath, file)
        if(dirName not in file and os.path.isfile(nowfile)):
            filename, filetype = os.path.splitext(file)
            if(filetype == '.jpg'):
                newname = 'sanhe-%s-%s' % (dirName, re.sub('[1,2]', '', file))
                os.rename(file,newname)
                count += 1
                print('处理文件：%s\\%s -> %s' % (dirName,file, newname))


dirs = os.listdir(cpath)

for file in dirs:
    nowdir = os.path.join(cpath, file)
    if(os.path.isdir(nowdir)):
        renameFile(file, nowdir)

print('当前共处理图片：' + str(count))
